/*
 ********************************************************************************
 * Copyright (c) 2013 Samsung Electronics, Inc.
 * All rights reserved.
 *
 * This software is a confidential and proprietary information of Samsung
 * Electronics, Inc. ("Confidential Information"). You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with Samsung Electronics.
 ********************************************************************************
 */

package adjust_volume;

import java.lang.ref.WeakReference;

import com.example.minimusicdemo.Fragment_playmain;
import com.example.minimusicdemo.Main_play;

import android.media.AudioManager;
import android.os.AsyncTask;
import android.os.SystemClock;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.SeekBar;
import android.widget.Toast;

import adjust_volume.Direction;
import adjust_volume.DrawerApplier;
import adjust_volume.DrawerOpener;

/**
 * The base class that supports basic drawer manipulation routines.
 */
public abstract class BaseDrawerApplier implements DrawerApplier {
	public static int isdisplay = 0;

	private final WeakReference<DrawerOpener> mDrawerOpener;

	public BaseDrawerApplier(DrawerOpener drawerOpener) {
		mDrawerOpener = new WeakReference<DrawerOpener>(drawerOpener);
	}

	@Override
	public final DrawerOpener getDrawerOpener() {
		return mDrawerOpener.get();
	}

	void openDrawerBasedOn(Direction direction) {

		final boolean leftGesture = Direction.LEFT.equals(direction);
		final boolean rightGesture = Direction.RIGHT.equals(direction);

		if (leftGesture) {

			if (isdisplay == 1) {
				if (Main_play.viewcontrolvolume.isShown()) {
					Main_play.viewcontrolvolume.setVisibility(View.GONE);
					isdisplay = 0;

				}
			} else {
				if (!Main_play.viewcontrolvolume.isShown()) {
					Main_play.viewcontrolvolume.setVisibility(View.VISIBLE);
				}
				int currentvolume = Main_play.audioManager
						.getStreamVolume(AudioManager.STREAM_MUSIC);
				Main_play.seekBarvolume.setProgress(currentvolume - 1);
				isdisplay = 2;
			}

		}
		if (rightGesture) {
			if (isdisplay == 2) {

				if (Main_play.viewcontrolvolume.isShown()) {
					Main_play.viewcontrolvolume.setVisibility(View.GONE);
					isdisplay = 0;

				}
			}

			else {
				if (!Main_play.viewcontrolvolume.isShown()) {
					Main_play.viewcontrolvolume.setVisibility(View.VISIBLE);
				}
				int currentvolume = Main_play.audioManager
						.getStreamVolume(AudioManager.STREAM_MUSIC);
				Main_play.seekBarvolume.setProgress(currentvolume + 1);
				isdisplay = 1;
			}
		}

	}
}